using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

//切换工具
public class SwitchTool : MonoBehaviour
{
    public Tool tool;
    private ToolController toolController;

    private void Start()
    {
        toolController = FindObjectOfType<PlayerController>().GetComponentInChildren<ToolController>();
        //修改当前按钮icon图片11
        GetComponent<Image>().sprite = tool.Icon;
        //绑定点击事件
        GetComponent<Button>().onClick.AddListener(ChangeTool);
    }

    //切换工具
    public void ChangeTool()
    {
        if (toolController != null)
        {
            if(toolController.GetComponent<SpriteRenderer>().sprite != tool.sprite){
                toolController.tool = tool;
                //修改工具角色手拿工具图片
                toolController.GetComponent<SpriteRenderer>().sprite = tool.sprite;
            }else{
                toolController.tool = null;
                toolController.GetComponent<SpriteRenderer>().sprite = null;
            }
            
        }else{

            Debug.LogWarning("没找到目标ToolController组件");
        }
    }

}
